<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>汉字转拼音</title>
    <script src="./Convert_Pinyin.js"></script>
</head>

<body>
    <p>强大的汉字转拼音工具参见：</p>
    <p>
        <a href="https://www.npmjs.com/package/pinyin-pro">pinyin-pro</a>
    </p>
    <!-- 插件引用 -->
    <br> 中文输入：<textarea id="keyword" cols="30" rows="10" onBlur="ConvertName()"></textarea>
    <br> 全写拼音：<textarea id="full" cols="30" rows="10"></textarea>
    <br> 简写拼音：<textarea id="simply" cols="30" rows="10"></textarea>
    <script>
        // 原理：unicode码的处理
        function ConvertName() {
            var keyword = document.getElementById('keyword').value;
            var full = pinyin.getFullChars(keyword); // 获取全写拼音
            var simply = pinyin.getCamelChars(keyword); // 获取简写拼音(提取首字母并大写)
            document.getElementById('full').value = full;
            document.getElementById('simply').value = simply;// 默认大写.可通过string.toLowerCase()转成小写
        }
    </script>
</body>

</html>